package com.yfq.springframework.context.support;

import com.yfq.springframework.beans.factory.ConfigurableListableBeanFactory;
import com.yfq.springframework.beans.support.DefaultListableBeanFactory;

/**
 * @author 姚凤桥
 * @date 2023/1/19 15:01
 * @description
 */
public abstract class AbstractRefreshableApplicationContext extends AbstractApplicationContext {
    private DefaultListableBeanFactory beanFactory;

    @Override
    protected void refreshBeanFactory() {
        DefaultListableBeanFactory defaultListableBeanFactory = createBeanFactory();
        //加载BeanDefinitions
        loadBeanDefinitions(defaultListableBeanFactory);

        this.beanFactory = defaultListableBeanFactory;
    }

    private DefaultListableBeanFactory createBeanFactory() {
        return new DefaultListableBeanFactory();
    }

    protected abstract void loadBeanDefinitions(DefaultListableBeanFactory beanFactory);

    @Override
    protected ConfigurableListableBeanFactory getBeanFactory() {
        return beanFactory;
    }
}
